﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;
using System.Threading;
using HomePage.Controllers;

namespace TGVR_Project.Controllers
{
    public class TestPerController : BaseController
    {
        private static readonly object _lock = new object();
        public string Index1()
        {
            AsyncManager.OutstandingOperations.Increment(1);
            return OperationAsync1();
        }
        public string Index2()
        {
            AsyncManager.OutstandingOperations.Increment(1);
            return OperationAsync2();
        }
        public ActionResult IndexCompleted(string Operation1, string Operation2)
        {
            ViewData["Operation1"] = Operation1;
            ViewData["Operation2"] = Operation2;
            return View("Index");
        }
        string OperationAsync1()
        {
            //lock (_lock)
            {
                AsyncManager.Parameters["Operation1"] = "Result1";
                AsyncManager.OutstandingOperations.Decrement();
                Thread.Sleep(10000);
            }
            
            //last line of this method
            return "1";
        }
        string OperationAsync2()
        {
            //lock (_lock)
            {
                AsyncManager.Parameters["Operation2"] = "Result2";
                AsyncManager.OutstandingOperations.Decrement();
                //Thread.Sleep(10000);
            }
            //last line of this method

            
            return "2";
        }
    }
}